package com.example.fw;

import java.util.ArrayList;
import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;

import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTreeOperator;

public class FolderHelper extends HelperBase{

	public FolderHelper(ApplicationManager applicationManager) {
		super(applicationManager);	
	}

	public Folders getFolders() {
		List<String>  list = new ArrayList<String>();
		JFrameOperator mainFrame = appManager.getApplication();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children) {
			list.add("" + child);
		}
		return new Folders(list);
	}

	public String createFolder(String folder) {
		appManager.getMenuHelper().initCreateFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JTextFieldOperator(dialog).setText(folder);
		new JButtonOperator(dialog, "OK").push();
		return waitMessageDialog("Warning", 4000);
	}

	public String deleteFolder(int folder) {		
		JFrameOperator mainFrame = appManager.getApplication();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		
	/*	Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children) {
			
				 tree.getSelectionPath();
				
			
		}*/

     /*   DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();*/		
		
	    TreePath path = tree.getPathForRow(folder);
	    tree.setSelectionPath(path);
	    
	    path.getLastPathComponent();    
		appManager.getMenuHelper().initDeleteFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JButtonOperator(dialog, "OK").push();
		return waitMessageDialog("Warning", 2000);	
		
	}

	

}
